package de.tum.in.eist.poll.client.views;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import de.tum.in.eist.poll.client.controllers.Controller;
import de.tum.in.eist.poll.client.views.widgets.UserWidget;
import de.tum.in.eist.poll.client.views.widgets.MenuWidget;

/**
 * the super class for all possible pages (=views)
 * it already implements a titlebar and encapsulates the children as center elements
 * @author Sebastian Hofstetter
 * 
 */
public abstract class View extends Composite {
	private VerticalPanel mainPanel = new VerticalPanel();

	private HorizontalPanel header = new HorizontalPanel();

	DialogBox notificationBox = new DialogBox(true);

	@Override
	protected void initWidget(Widget widget) {
		// Notification Dialog
		notificationBox.setAnimationEnabled(true);
		notificationBox.setGlassEnabled(true);
		

		header.setStylePrimaryName("header");
		if (Controller.controller.loggedIn()) {
			header.add(new MenuWidget());
		}
		header.add(new UserWidget());
		mainPanel.add(header);
		widget.addStyleName("center");
		mainPanel.add(widget);

		super.initWidget(mainPanel);
		getElement().setId("view");
	}
	
	/**
	 * notifys the client by showing a dialogbox
	 */
	public void notifyClient(String text, Image image) {
		notificationBox.setText(text);
		notificationBox.add(image);
		notificationBox.center();
	}
    
}